package com.G_CN06.mvc.controller;


import com.G_CN06.commonUtil.commonResultConfig.CommonResult;
import com.G_CN06.mvc.entity.User;
import com.G_CN06.mvc.service.UserService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Huang
 * @since 2022-11-15
 */
@RestController
@CrossOrigin
@RequestMapping("/mvc/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public CommonResult login(String phoneNumber , String password, HttpServletRequest request){
        CommonResult r = new CommonResult();
        User user = userService.login(phoneNumber,password);
        if (user!=null){
            HttpSession session = request.getSession();
            session.setAttribute("LoadingUser",user);
            return r.ok();
        }
        return r.error();
    }
}

